package com.eleadmin.gps.controller;

import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.common.core.config.WebSocketServer;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.gps.dao.CarPosition;
import com.eleadmin.gps.param.CarpositionParam;
import com.eleadmin.gps.serivce.MapperService;
import com.eleadmin.order.entity.ApplyCustoms;
import com.eleadmin.order.service.ApplyCustomsService;
import com.eleadmin.order.service.ContainerBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 *
 * 报关
 * @author : Doman
 * @date : 2023-05-06 10:49:33
 * @version ：1.0
 */

@Api(tags = "地图")
@RestController
@RequestMapping("/api/order/mapper")
public class MapperController extends BaseController {

    @Autowired
    private ApplyCustomsService applyCustomsService;
    @Autowired
    private MapperService mapperService;
    @Autowired
    private ContainerBillService containerBillService;

    @PreAuthorize("hasAuthority('order:mapper:list')")
    //@ApiOperation("分页查询报关")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, ApplyCustoms applyCustoms) throws Exception{
        return applyCustomsService.list(page, applyCustoms, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:mapper:list')")
    //@ApiOperation("查询全部报关")
    @GetMapping()
    public JsonResult list(ApplyCustoms applyCustoms){
        return applyCustomsService.list(applyCustoms, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:mapper:list')")
    @GetMapping("carMapper")
    public void carMapper(ApplyCustoms applyCustoms){
        containerBillService.carMapper();
    }

    /**
     *  "vno: 车牌 浙Be2343\n"+
     * @param carPosition
     * @return
     */
//    @PreAuthorize("hasAuthority('order:mapper:list')")
    @GetMapping("transTimeManageV3")
    public JsonResult transTimeManageV3(CarpositionParam carPosition){
//        WebSocketServer.sendInfo("1111","container");
//        WebSocketServer.sendInfo("22222","mapper");
        return mapperService.transTimeManageV3(carPosition);
    }

    /**
     *  "vno: 车牌 浙Be2343\n"+
     *  "date1: 时间\n"+
     *  "date2: 时间\n"+
     * @param carPosition
     * @return
     */
//    @PreAuthorize("hasAuthority('order:mapper:list')")
    @GetMapping("goodsTransferTrack")
    public JsonResult goodsTransferTrack(CarpositionParam carPosition){
        return mapperService.goodsTransferTrack(carPosition);
    }

    /**
     *  "vno: 车牌 浙Be2343\n"+
     *  "date1: 时间\n"+
     *  "date2: 时间\n"+
     * @param carPosition
     * @return
     */
//    @PreAuthorize("hasAuthority('order:mapper:list')")
    @GetMapping("trajectory")
    public JsonResult trajectory(CarPosition carPosition){
        return mapperService.trajectory(carPosition);
    }

    @PreAuthorize("hasAuthority('order:mapper:list')")
    //@ApiOperation("根据id查询报关")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return applyCustomsService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:mapper:save')")
    @OperationLog
    @ApiOperation(value ="添加报关")
    @PostMapping()
    public JsonResult save(@RequestBody ApplyCustoms applyCustoms) {
        try {
            return applyCustomsService.save(applyCustoms, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:mapper:update')")
    @OperationLog
    @ApiOperation(value ="修改报关")
    @PutMapping()
    public JsonResult update(@RequestBody ApplyCustoms applyCustoms) {
        try {
            return applyCustomsService.update(applyCustoms, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:mapper:remove')")
    @OperationLog
    @ApiOperation(value ="删除报关")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return applyCustomsService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
